import http from '../../util/request.js';
import alert from '../../util/alert.js';
var WxParse = require('../../../wxParse/wxParse.js');
Page({
  data:{
    IsFavorite:0,
    article: []
  },
  onLoad:function(options){
    // 页面初始化 options为页面跳转所带来的参数
    http.get('api', { 
      r:'home.articleinfo',
      article_id: options.article_id }).then(data => {
        console.log(data);
      this.setData({
        IsFavorite: data.IsFavorite,
        article: data 
        });
      WxParse.wxParse('content', 'html', this.data.article.article_content, this, 3);
    });
  },
  /**
 * 收藏
 */
  favorite: function (e) {
    var that = this;
    var id = e.target.dataset.id;
    var IsFavorite = that.data.IsFavorite;
    console.log('fav');

    var params = {
      r:'home.Favoritedo',
      fav_type: 'article',
      type_key: id,
      IsFavorite:IsFavorite == 1 ? 0 : 1
    }
    http.get('api', params).then(data => {
      this.setData({ IsFavorite: IsFavorite == 1 ? 0 : 1 });
    });
  },
})